package com.kerrykidz.common.finger;

import java.io.File;

/**
 * 方立数码指纹服务器调用接口
 * 
 * @author 
 *
 */
public class FerlyAlgJniCall {

	public static String webPath = "";
	
	static {
		try {
			
			if(File.separator.equals("/")){ 
				//linux
				String path= "/"+getRealPath()+"WEB-INF/classes/finger/libFLAlgMatch.so";
				System.out.println("------加载指纹校验算法测试！"+path);
				System.load(path);
			}else{
				//window
				String path= getRealPath() +"WEB-INF/classes/finger/libFLAlgMatch.dll";
				System.out.println("DLL路径"+path);
				System.load(path);
			}
			System.out.println("------加载指纹校验算法成功！");
		} catch (UnsatisfiedLinkError e) {
			System.out.println("--加载指纹算法失败: "+ e.toString());
		}
	}
	
	/**
	 * @return 得到工程当前目录
	 */
	public static String getRealPath() {
		String path = FerlyAlgJniCall.class.getResource("").getPath();
		path = path.substring(1, path.indexOf("WEB-INF/"));
		return path;
	}

	public FerlyAlgJniCall() {
		super();
	}

	
	/**
	 * 指纹比对函数
	 * @param pRegBuf 指纹特征数据
	 * @param pVerBuf 指纹特征数据
	 * @param nLevel 比对级别
	 * @return 0.成功，1.失败
	 */
	public native int FlAlgMatch(String pRegBuf,String pVerBuf,int nLevel);

	private static FerlyAlgJniCall fm = null;
	public static FerlyAlgJniCall getInstatnce() {
		if (null == fm) {
			fm = new FerlyAlgJniCall();
		}
		return fm;
	}
	
	
	/**
	 * 测试使用
	 * @param args
	 */
	public static void main(String[] args) {
		
	}
}